import { getMockStat } from 'api/test1'

interface IStatStore {
  boardDict: {
    key: string
    name: string
    bg: string
    unit?: string
    tooltip?: string
    selected?: boolean
  }[]
  statValue: Record<string, number>
}

export const useStat = defineStore('stat', {
  state: () => {
    const data = reactive<IStatStore>({
      boardDict: [
        {
          key: 'value1',
          name: '数据项1',
          bg: 'bg-blue-300',
          tooltip: '数据项1的意思就是....这样子',
        },
        {
          key: 'value2',
          name: '数据项2',
          bg: 'bg-green-300',
          unit: '人',
          tooltip: '数据项2的意思就是....这样子',
        },
        {
          key: 'value3',
          name: '数据项3',
          bg: 'bg-green-300',
          unit: '%',
        },
        {
          key: 'value4',
          name: '数据项4',
          bg: 'bg-amber-300',
          unit: '元',
        },
        {
          key: 'value5',
          name: '数据项5',
          bg: 'bg-amber-300',
          unit: '次',
        },
        {
          key: 'value6',
          name: '数据项6',
          bg: 'bg-amber-300',
          unit: '次',
        },
      ],
      statValue: {},
    })

    async function handleGetData() {
      const statValue = await getMockStat()
      Object.assign(data, { statValue })
    }

    return {
      ...toRefs(data),
      handleGetData,
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'XXXXXXX-STAT',
        storage: localStorage,
      },
    ],
  },
})
